package com.jyx.awt;

import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.List;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Fram {

	public static void main(String[] args) {
		// frame
		Frame frame = new NewFrame();
		frame.setLayout(new GridLayout(2, 1));
		// panel
		Panel p1 = new Panel();
		p1.setBackground(Color.red);
		p1.setName("p1");
		p1.setSize(200, 200);
		
		Panel p2 = new Panel();
		p2.setBackground(Color.black);
		
//		frame.add(p1, BorderLayout.EAST);
//		frame.add(p2, BorderLayout.WEST);
		// button
		Button b1 = new Button("hello world");
		b1.setEnabled(true);
		b1.setBackground(Color.gray);
		b1.setSize(1, 1);
		b1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				System.exit(1);
			}
		});
		frame.add(b1);
		// label
		Label label = new Label("this is a label");
		label.setAlignment(Label.LEFT);
		frame.add(label);
		// textarea
		TextArea ta = new TextArea();
		ta.setBackground(Color.white);
		frame.add(ta);
		// checkbox
		Checkbox cb1 = new Checkbox("reader", true);
		Checkbox cb2 = new Checkbox("sleep", false);
		Checkbox cb3 = new Checkbox("drink tea", true);
		Checkbox cb4 = new Checkbox("running", false);
		
		frame.add(cb1);
		frame.add(cb2);
		frame.add(cb3);
		frame.add(cb4);
		// list
		List list = new List();
		list.add("2007");
		list.add("2008");
		list.add("2009");
		list.add("2010");
		frame.add(list);
		
		frame.setSize(500, 300);
		frame.setVisible(true);
		
		Frame f = new Frame("GridBagConstraints Demo");
		f.setLayout(new GridLayout(3, 3));
//		for (int i = 0; i < 9; i++) {
//			f.add(new Button(i+1+"....."));
//		}
		// GridBagConstraints
		GridBagConstraints gbcs = new GridBagConstraints();
		gbcs.gridx=0;
		gbcs.gridy=0;
		f.add(new Button("button one"),gbcs);
		gbcs.gridx=1;
		gbcs.gridy=0;
		f.add(new Button("button two"),gbcs);
		gbcs.gridx=0;
		gbcs.gridy=1;
		f.add(new Button("button three"),gbcs);
		gbcs.gridx=1;
		gbcs.gridy=1;
		f.add(new Button("button four"),gbcs);
		
		f.setSize(500, 500);
		f.setVisible(true);
	}
}

class NewFrame extends Frame {
	public NewFrame(){
		setTitle("标题！");
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		int screenHeight = screenSize.height;
		int screenWidth = screenSize.width;
		setSize(screenWidth / 2, screenHeight / 2);
		setLocation(screenWidth/4,screenHeight/4);
		this.repaint();
	}
}